package com.ruoyi.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.HosBunk;
import com.ruoyi.hospital.service.IHosBunkService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 床位信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@RestController
@RequestMapping("/hospital/bunk")
public class HosBunkController extends BaseController
{
    @Autowired
    private IHosBunkService hosBunkService;

    /**
     * 查询床位信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:list')")
    @GetMapping("/list")
    public TableDataInfo list(HosBunk hosBunk)
    {
        startPage();
        List<HosBunk> list = hosBunkService.selectHosBunkList(hosBunk);
        return getDataTable(list);
    }

    /**
     * 查询所有有效的床位 不分页 用于分配信息的添加操作 下拉
     * @param hosBunk
     * @return
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:list')")
    @GetMapping("/listEffectAll")
    public AjaxResult listEffectAll(HosBunk hosBunk) {
        // 查询所有有效的床位
        hosBunk.setStatus("0");
        return AjaxResult.success(hosBunkService.selectHosBunkList(hosBunk));
    }

    /**
     * 查询所有床位 不分页 用于分配信息条件查询 下拉
     * @param hosBunk
     * @return
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(HosBunk hosBunk) {
        return AjaxResult.success(hosBunkService.selectHosBunkList(hosBunk));
    }

    /**
     * 导出床位信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:export')")
    @Log(title = "床位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HosBunk hosBunk)
    {
        List<HosBunk> list = hosBunkService.selectHosBunkList(hosBunk);
        ExcelUtil<HosBunk> util = new ExcelUtil<HosBunk>(HosBunk.class);
        util.exportExcel(response, list, "床位信息数据");
    }

    /**
     * 获取床位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:query')")
    @GetMapping(value = "/{bunkId}")
    public AjaxResult getInfo(@PathVariable("bunkId") Long bunkId)
    {
        return success(hosBunkService.selectHosBunkByBunkId(bunkId));
    }

    /**
     * 新增床位信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:add')")
    @Log(title = "床位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HosBunk hosBunk)
    {
        return toAjax(hosBunkService.insertHosBunk(hosBunk));
    }

    /**
     * 修改床位信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:edit')")
    @Log(title = "床位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HosBunk hosBunk)
    {
        return toAjax(hosBunkService.updateHosBunk(hosBunk));
    }

    /**
     * 删除床位信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:bunk:remove')")
    @Log(title = "床位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bunkIds}")
    public AjaxResult remove(@PathVariable Long[] bunkIds)
    {
        return toAjax(hosBunkService.deleteHosBunkByBunkIds(bunkIds));
    }
}
